home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9830 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: web.cae.ca!usenet
  2. From: fraserh@cae.ca (Fraser Hutchinson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: unsigned char question
  5. Date: 4 Mar 1996 18:21:36 GMT
  6. Organization: CAE Electronics Ltd.
  7. Message-ID: <4hfcbg$t53@web.cae.ca>
  8. References: <3136864B.7154@eds.com>
  9. NNTP-Posting-Host: pch63.cae.ca
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <3136864B.7154@eds.com>, lnusmsc.phoeks01@eds.com says...
  15. >
  16. >This is a basic question but one I cannot answer.  I am using VC++ 2.0
  17. >and I wish to assign a string to a variable of type UCHAR * (which is an 
  18. unsigned char 
  19. >within ODBC).  The code is as follows
  20. >
  21. >UCHAR * server;
  22. >
  23. >server = "jmbademo";
  24.  
  25. Two problems here - do you not have to allocate memory for the assignment
  26. statement?  (Maybe I am missing something here)... 
  27.  
  28. For example, this should work:
  29.  
  30.   UCHAR *server = (UCHAR *)"jmbademo";        // static declaration
  31.  
  32. Alternatively, I believe you must do this:
  33.  
  34.   UCHAR *server;                // dynamic allocation
  35.  
  36.   server = new UCHAR[strlen(jmbademo")+1];
  37.   strcpy(server, (UCHAR *)"jmbdemo");
  38.  
  39.  
  40.  
  41. >When I attempt to compile this piece of code, I receive the following error:
  42. >
  43. >C:\cgi\Envvars\Envvar.cpp(417) : error C2446: '=' : no conversion from 
  44. 'char[9]' to 
  45. >'unsigned char*'
  46.  
  47. This is the second problem.
  48.  
  49. To the compiler, char * and unsigned char * are two different typws, you have 
  50. to cast them as I did above.
  51.  
  52. Regards,
  53.  
  54. Fraser
  55.  
  56.